import objectUtils from "@/utils/object/index.js";

export default objectUtils.freeze({
	distance: (lat1, lon1, lat2, lon2, isKilometre) => {
		let R = isKilometre ? 6371 : 6371e3;
		let φ1 = (lat1 * Math.PI) / 180;
		let φ2 = (lat2 * Math.PI) / 180;
		let Δφ = ((lat2 - lat1) * Math.PI) / 180;
		let Δλ = ((lon2 - lon1) * Math.PI) / 180;
		let a = Math.sin(Δφ / 2) * Math.sin(Δφ / 2) + Math.cos(φ1) * Math.cos(φ2) * Math.sin(Δλ / 2) * Math.sin(Δλ / 2);
		let c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
		let distance = R * c;
		return distance;
	}
});